package com.qzsf.backend.mapper.sql;

import org.apache.ibatis.jdbc.SQL;
/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/19 21:56 周二
 * @Email 1429278462@qq.com
 * @Remark 条件筛选活动
 * @Version 1.0
 */
public class EventSqlProvider {
    public String getEventsByCondition(Integer status, Integer typeId, Integer organizerId) {
        return new SQL() {{
            SELECT("a.id, a.typeId, b.type as typeName, a.name, a.number, a.remaining, a.location, a.description, a.pics, a.start_time, a.end_time, a.hours, a.auth_id, c.name as organizerName,c.pic as organizerPic");
            FROM("event a LEFT JOIN event_type b ON a.typeId = b.id LEFT JOIN organizer_profile c ON a.auth_id = c.id");

            // 根据 status 设置不同的时间条件
            if (status != null && status == 1) {
                WHERE("a.start_time > NOW()");
            } else if (status != null && status == 2) {
                WHERE("a.start_time <= NOW() AND a.end_time >= NOW()");
            } else if (status != null && status == 3) {
                WHERE("a.end_time < NOW()");
            }

            if (typeId != null && typeId != 0) {
                WHERE("a.typeId = #{typeId}");
            }

            if (organizerId != null && organizerId != 0) {
                WHERE("a.auth_id = #{organizerId}");
            }
        }}.toString();
    }
}
